package com.renzhebiao.lkang.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.plugins.Page;
import com.renzhebiao.lkang.base.BaseService;
import com.renzhebiao.lkang.entity.ServiceProjectPO;
import com.renzhebiao.lkang.mapper.ServiceProjectMapper;
import com.renzhebiao.lkang.page.PageDTO;
import com.renzhebiao.lkang.page.PaginationDTO;
import com.renzhebiao.lkang.query.ServiceProjectQuery;
import com.renzhebiao.lkang.request.RequestCache;
import com.renzhebiao.lkang.service.IServiceProjectService;
import com.renzhebiao.lkang.utils.BeanCopys;

/**
 * <p>
 * 服务（首页二层图文） 服务实现类
 * </p>
 *
 * @author renzhebiao123
 * @since 2018-10-23
 */
@Service
public class ServiceProjectService extends BaseService<ServiceProjectPO> implements IServiceProjectService {

    @Autowired
    ServiceProjectMapper serviceProjectMapper;

    @Override
    public void add(ServiceProjectPO po) {
        po.allEx(RequestCache.userId());
        this.serviceProjectMapper.insert(po);
    }

    @Override
    public void edit(ServiceProjectPO po) {
        po.updated(RequestCache.userId());
        this.serviceProjectMapper.updateById(po);
    }

    @Override
    public void delete(Long id) {
        this.deleteByLogic(id, ServiceProjectPO.class);
    }

    @Override
    public List<ServiceProjectPO> getServiceProjectList(ServiceProjectQuery po) {

        return this.serviceProjectMapper.selectByMap(BeanCopys.toMap(po));
    }

    @Override
    public ServiceProjectPO getServiceProject(Long id) {

        return this.serviceProjectMapper.selectById(id);
    }

    @Override
    public PageDTO<ServiceProjectPO> getServiceProjectByPage(PaginationDTO<ServiceProjectQuery, Void> paging) {

        Page<ServiceProjectPO> page = this.getPage(paging);
        List<ServiceProjectPO> pos = this.serviceProjectMapper.getServiceProjectByPage(page, page.getCondition());
        return this.getPage(page, pos);
    }

}
